package calendar.model;

import calendar.commands.calendar.CreateCalendar;
import calendar.commands.calendar.DeleteCalendar;
import calendar.commands.calendar.ReadCalendars;
import calendar.commands.calendar.UpdateCalendar;
import com.google.api.services.calendar.model.Calendar;
import model.Entity;

public class Calendars extends Entity<String, Calendar> {
    private com.google.api.services.calendar.Calendar client;
    private Calendar calendar;

    Calendars() {
        super(Calendar[].class, Calendar.class);
    }

    public void setClient(com.google.api.services.calendar.Calendar client) {
        this.client = client;
    }

    public void setCalendar(Calendar calendar) {
        this.calendar = calendar;
    }

    public CreateCalendar getCreateCommand() {
        return (CreateCalendar) new CreateCalendar(client)
                .onFinished((o, arg) -> {
                    calendar = (Calendar) arg;
                });
    }

    public ReadCalendars getReadCommand() {
        return new ReadCalendars(client);
    }

    public UpdateCalendar getUpdateCommand() {
        return (UpdateCalendar) new UpdateCalendar(client).setCalendar(calendar);
    }

    public DeleteCalendar getDeleteCommand() {
        return (DeleteCalendar) new DeleteCalendar(client).setCalendar(calendar);
    }

    @Override
    protected String getKey(Calendar calendar) {
        return calendar.getId();
    }

    @Override
    protected void parse() {
    }
}
